package com.louis.testvalidation;

import org.junit.jupiter.api.Test;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;

/**
 * @author XRY
 * @date 2023年06月29日11:50
 */
public class TestPerson {
    @Test
    public void testValidation(){
        //创建Person对象
        Person person = new Person();
        person.setAge(30);
        person.setName(null);
        //创建person对应对象
        DataBinder binder = new DataBinder(person);
        //设置校验器
        binder.setValidator(new PersonValidator());
        //调用方法、执行校验
        binder.validate();
        //输出校验结果
        BindingResult result = binder.getBindingResult();
        System.out.println("result.getAllErrors() = " + result.getAllErrors());
    }
    /*
    * Empty.name,name Empty.java.lang.String,name Empty]; arguments []; default message [name is null]]
    * */
}
